'use strict';

const Controller = require('egg').Controller;
const w = require("ws")
// const path = require("path")

// const fs = require("fs")

// var svgCaptcha = require('svg-captcha');
// const { url } = require('inspector');

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = '騎蝸牛追导弹';
    console.log(w);
  }

  async search() {
    // var txt = this.ctx.request.query.department
    var txt = this.ctx.request.query
    console.log(txt)

    if (!txt.sec) {
      let sql = `select * from goods WHERE updata='${txt.department}'`
      let res = await this.ctx.app.mysql.query(sql)
      this.ctx.body = {
        sql: res
      }
    } else {
      if (txt.table == 'promble') {
        let sql = `SELECT  
        goods.img,goods.title,goods.updata,goods.type,goods.type2,promble.prob
        FROM  goods inner join promble 
        on goods.id=promble.did;`
        // did
        let res = await this.ctx.app.mysql.query(sql)
        // 大家都在问
        this.ctx.body = {
          sql: res
        }
      } else {
        let sql = `select * from ${txt.table} WHERE ${txt.field} LIKE '%${txt.department}%'`
        let res = await this.ctx.app.mysql.query(sql)

        // console.log("执行力",  res,typeof(res))
        // console.log(res)
        this.ctx.body = {
          sql: res
        }
      }
    }
  }

}









module.exports = HomeController;
